/*
 * Copyright (C) 2008  Wang Hoi <fearee@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
*/
#include "memcache.h"
#include <unistd.h>
#include <QtCore>

class CacheCB: public QObject
{
    Q_OBJECT
public Q_SLOTS:
    void onValueGot(const QByteArray &key, const QByteArray &value) {
        qDebug() << "Got -- Key: " << key << " Value: " << value;
    }
    void onValueSet(const QByteArray &key) {
        qDebug() << "Set -- Key: " << key;
    }
    void onError(const QByteArray &err) {
        qDebug() << "Error -- " << err;
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    MemCache cacher;
    CacheCB cb;
    QObject::connect(&cacher, SIGNAL(errorGot(const QByteArray&)), &cb, SLOT(onError(const QByteArray&)));
    QObject::connect(&cacher, SIGNAL(valueGot(const QByteArray&, const QByteArray&)), &cb,
                     SLOT(onValueGot(const QByteArray&, const QByteArray&)));
    QObject::connect(&cacher, SIGNAL(valueSet(const QByteArray&)), &cb, SLOT(onValueSet(const QByteArray&)));
    QByteArray addr("127.0.0.1:11211");
    QList<QByteArray> lists;
    lists << addr;
    cacher.setServers(lists);
    QString a = QString::fromUtf8("楼上");
    qDebug() << qPrintable(a);
    cacher.set("add", "abfewqgc");
    usleep(100*1000);
    cacher.get("add");
    app.exec();
}

#include "test_cache.moc"
